/***************************************************************************
 *   Copyright (C) 2009 by Zheng Yonglei
 *   zhengyonglei@gmail.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include <QtGui>
#include <QApplication>
#include <QTextCodec>

#include "ReciteGREWords.h"
#include "WordManager.h"
#include "DictManager.h"
#include "StaticModule.h"
#include "Options.h"
#include "Logger.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));

    StaticModule<Logger>::init();
    StaticModule<Logger>::getInstance().add("MainLog", new LogFile("MainLog.txt"));
    LOG_REF.setThreadID("Main");

	QTranslator translator;
	StaticModule<Options>::init();
	OPT.splash.show();
	if (OPT.language == QString("Chinese"))
	{
		translator.load("ReciteGREWords_zh_CN");
		a.installTranslator(&translator);
	}

	StaticModule<SQLiteDB>::init();
	StaticModule<DictManager>::init();
	StaticModule<DictOptions>::init();

	//Using pointer because w must be deleted before other modules
    ReciteGREWords* w = new ReciteGREWords();
    w->show();
    OPT.splash.finish(w);
    w->showLoginDialog();

    int exitVal = a.exec();

    delete w;

    StaticModule<DictOptions>::destroy();
    StaticModule<DictManager>::destroy();
    StaticModule<SQLiteDB>::destroy();
	StaticModule<Options>::destroy();
	StaticModule<Logger>::destroy();

    return exitVal;
}
